package com.cgly.medical.controller;


import com.cgly.medical.domain.China;
import com.cgly.medical.entity.CityEntity;
import com.cgly.medical.model.CityModel;
import com.cgly.medical.service.ChinaService;
import com.cgly.medical.service.CityService;
import com.cgly.medical.util.Msg;
import com.github.pagehelper.PageInfo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;

@RestController
@RequestMapping("/citys")
@CrossOrigin  //解决跨域问题
public class CityController {

    @Resource
    private CityService cityService;

    @Resource
    private ChinaService chinaService;

    //查询所有城市信息
    @GetMapping("selectAll/{page}/{limit}")
    public Msg getAll(@PathVariable Integer page,@PathVariable Integer limit){
        Msg msg=cityService.getAll(page,limit);
        return msg;
    }

    //条件查询对应的城市信息
    @PostMapping("getsomeChina/{page}/{limit}")
    public Msg getsomeChina(@PathVariable Integer page,@PathVariable Integer limit,@RequestBody(required = false) China china){
        china.setPn(page);
        china.setSize(limit);
        if((china.getId()==null&&china.getName()==null)||(china.getId()==null&&china.getName().length()==0)){
            return cityService.getAll(page,limit);
        }else{
            Msg msg = chinaService.getSomeChina(china);
            return msg;
        }
    }

    //条件查询对应的城市信息
    @PostMapping("getAllChina")
    public Msg getAllChina(@RequestBody(required = false) China china){

            Msg msg = chinaService.getAllChina(china);
            return msg;

    }

    //条件查询对应的城市信息
    @GetMapping("getAllChinaByPId")
    public Msg getAllChinaByPId(){
        Msg chinas = chinaService.getAllChinaByPId();
        return chinas;

    }


    //根据cityNumber删除城市信息
    @DeleteMapping("delete")
    public Msg deleteCityAndChina(@RequestBody(required = false) String cityNumber){
        int number = Integer.parseInt(cityNumber);
        Msg msg = cityService.deleteCityByNumber(number);
        return msg;
    }
}
